﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NovoSerDes.A2B.propeties_page.uipage
{
    public partial class audio_config_general_view : UIPage
    {
        public audio_config_general_view()
        {
            InitializeComponent();

            this.combox_TDM_Channel_Size.SelectedIndex = 0;
            this.combox_TDM_Mode.SelectedIndex = 0;

            imgbtn_Sync_polarity.Image = imageList1.Images[0];
            imgbtn_DRXn_Sampling_BCLK.Image = imageList1.Images[0];
            imgbtn_DTXn_Change_BCLK.Image = imageList1.Images[0];
        }

        private void btn_Sync_Polarity_Click(object sender, EventArgs e)
        {
            if(this.btn_Sync_Polarity.Text == "Falling Ed")
            {
                this.btn_Sync_Polarity.Text = "Rising Edg";
                this.imgbtn_Sync_polarity.Image = this.imageList1.Images[1];
            }
            else
            {
                this.btn_Sync_Polarity.Text = "Falling Ed";
                this.imgbtn_Sync_polarity.Image = this.imageList1.Images[0];
            }
        }

        private void btn_DRXn_Sampling_BCLK_Click(object sender, EventArgs e)
        {
            if (this.btn_DRXn_Sampling_BCLK.Text == "Falling Ed")
            {
                this.btn_DRXn_Sampling_BCLK.Text = "Rising Edg";
                this.imgbtn_DRXn_Sampling_BCLK.Image = this.imageList1.Images[1];
            }
            else
            {
                this.btn_DRXn_Sampling_BCLK.Text = "Falling Ed";
                this.imgbtn_DRXn_Sampling_BCLK.Image = this.imageList1.Images[0];
            }
        }

        private void btn_DTXn_Change_BCLK_Click(object sender, EventArgs e)
        {
            if (this.btn_DTXn_Change_BCLK.Text == "Falling Ed")
            {
                this.btn_DTXn_Change_BCLK.Text = "Rising Edg";
                this.imgbtn_DTXn_Change_BCLK.Image = this.imageList1.Images[1];
            }
            else
            {
                this.btn_DTXn_Change_BCLK.Text = "Falling Ed";
                this.imgbtn_DTXn_Change_BCLK.Image = this.imageList1.Images[0];
            }
        }

        private void btn_Enable_Disable(object sender,EventArgs e)
        {
            UIButton button = (UIButton)sender;
            if(button != null)
            {
                if(button.Text == "Enabled")
                {
                    button.Text = "Disabled";
                    button.FillColor = Color.LightCoral;
                }
                else
                {
                    button.Text = "Enabled";
                    button.FillColor = Color.LawnGreen;
                }
            }
        }

        private void uiTrackBar1_ValueChanged(object sender, EventArgs e)
        {
            this.txtbox_Tx_Offset.Text = this.bar_Tx_Offset.Value.ToString();
        }

        private void txtbox_Tx_Offset_TextChanged(object sender, EventArgs e)
        {
            if (this.txtbox_Tx_Offset.Text.IsNumber() && this.txtbox_Tx_Offset.Text.ToInt() <= 100 && this.txtbox_Tx_Offset.Text.ToInt() >=0)
            {
                int value = this.txtbox_Tx_Offset.Text.ToInt();
                if (value <= 100 && value >=0)
                {
                    this.bar_Tx_Offset.Value = value;
                }
            }
            else
            {
                this.txtbox_Tx_Offset.Text = "0";
                this.txtbox_Tx_Offset.SelectionStart = this.txtbox_Tx_Offset.Text.Length; // 光标移动到文本末尾
            }
        }

        private void bar_Rx_Offset_ValueChanged(object sender, EventArgs e)
        {
            this.txtbox_Rx_Offset.Text = this.bar_Rx_Offset.Value.ToString();
        }

        private void txtbox_Rx_Offset_TextChanged(object sender, EventArgs e)
        {
            if (this.txtbox_Rx_Offset.Text.IsNumber() && this.txtbox_Rx_Offset.Text.ToInt() <= 100 && this.txtbox_Rx_Offset.Text.ToInt() >= 0)
            {
                int value = this.txtbox_Rx_Offset.Text.ToInt();
                if (value <= 100 && value >= 0)
                {
                    this.bar_Rx_Offset.Value = value;
                }
            }
            else
            {
                this.txtbox_Rx_Offset.Text = "0";
                this.txtbox_Rx_Offset.SelectionStart = this.txtbox_Rx_Offset.Text.Length; // 光标移动到文本末尾
            }
        }
    }
}
